#include<string>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
void sortColors(vector<int>& nums) {
    int left = -1, key = 0, right = nums.size();
    while (key < right)
    {
        if (nums[key] == 0)
            swap(nums[++left], nums[key++]);
        else if (nums[key] == 1)
            key++;
        else
            swap(nums[--right], nums[key]);
    }
}
class Solution {
public:
    int findKthLargest(vector<int>& nums, int k) {
        srand(time(NULL));
        return qsort(nums, 0, nums.size() - 1, k);
    }
    int qsort(vector<int>& nums, int l, int r, int k) {
        if (l == r) return nums[l];
        int left = l - 1, right = r + 1, sign = l;
        int key = Getrandom(nums, l, r);
        while (sign < right) {
            if (nums[sign] < key)
                swap(nums[++left], nums[sign++]);
            else if (nums[sign] == key)
                sign++;
            else
                swap(nums[sign], nums[--right]);
        }
        if (r - right + 1 >= k)
            return qsort(nums, right, r, k);
        else if (r - left >= k)
            return key;
        else
            return qsort(nums, l, left, k - (r - left));
    }
    int Getrandom(vector<int>& nums, int left, int right) {
        int x = rand();
        return nums[x % (right - left + 1) + left];
    }
};
int main()
{
    //vector<int> v = { 5,2,3,1 };
    //vector<int> d= sortArray(v);
    vector<int> v = masterMind("RGBY", "GGRR");
    return 0;
}
